//
//  DetailFreeTrailView.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/10.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "DetailFreeTrailView.h"
#import "CommonMacro.h"
#import "UIImageView+WebCache.h"
#import "DetailFreeModel.h"

@interface DetailFreeTrailView()
@property (nonatomic,strong) UIImageView *bigImageView;
@property (nonatomic,strong) UIView *middleView;
@property (nonatomic,strong) UIImageView *brandImageView;
@property (nonatomic,strong) UILabel *titlLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *specificationsLabel;
@property (nonatomic,strong) UILabel *fitAgeLabel;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UIView *timeAndNumView;
@property (nonatomic,strong) UILabel *trailNumLabel;
@property (nonatomic,strong) UILabel *applyLabel;
@property (nonatomic,strong) UILabel *overTime;

@end
@implementation DetailFreeTrailView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addTopSubViews];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)layoutSubviews
{
    [self valueForSubviews];
}

- (void)addTopSubViews
{
   //1.产品图片
    self.bigImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.frame.size.width, self.frame.size.height*0.43)];
//    self.bigImageView.backgroundColor = [UIColor redColor];
    [self addSubview:self.bigImageView];
    
    //2.小商标图片 标题 时间  规格  试用年龄 价钱
    self.middleView = [[UIView alloc] initWithFrame:CGRectMake(self.bigImageView.frame.origin.x, self.bigImageView.frame.size.height+self.bigImageView.frame.origin.y+3, self.bigImageView.frame.size.width, self.bigImageView.frame.size.height*0.5)];
//    middleView.backgroundColor = [UIColor cyanColor];
    [self addSubview:self.middleView];
    
    //2.1小商标图片
    self.brandImageView = [[UIImageView alloc] initWithFrame:CGRectMake(3, 2, self.middleView.frame.size.width*0.3, self.middleView.frame.size.height-4)];
//    self.brandImageView.backgroundColor = [UIColor greenColor];
    [self.middleView addSubview:self.brandImageView];
    
    //2.2标题
    
    self.titlLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.brandImageView.frame.origin.x+2+self.brandImageView.frame.size.width, self.brandImageView.frame.origin.y-2, self.middleView.frame.size.width*0.8, self.brandImageView.frame.size.height*0.2)];
//    titlLabel.backgroundColor = [UIColor blueColor];
    self.titlLabel.textColor = UIColorWithRGBA(117, 117, 117, 1);
    self.titlLabel.font = [UIFont systemFontOfSize:16];
    [self.middleView addSubview:self.titlLabel];
    
    //2.3时间
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titlLabel.frame.origin.x, self.titlLabel.frame.size.height+self.titlLabel.frame.origin.y+4, self.titlLabel.frame.size.width, self.titlLabel.frame.size.height*0.9)];
//    timeLabel.backgroundColor = [UIColor redColor];

    self.timeLabel.textColor = UIColorWithRGBA(186, 186, 186, 1);
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    [self.middleView addSubview:self.timeLabel];
    
    //2.4规格
    self.specificationsLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.timeLabel.frame.origin.x, self.timeLabel.frame.origin.y+self.timeLabel.frame.size.height+4,self.middleView.frame.size.width*0.3,self.middleView.frame.size.height*0.2)];
    self.specificationsLabel.textColor = UIColorWithRGBA(186, 186, 186, 1);
    self.specificationsLabel.font = [UIFont systemFontOfSize:12];
//    specificationsLabel.backgroundColor = [UIColor greenColor];
    [self.middleView addSubview:self.specificationsLabel];
    
    //2.5试用年龄
    self.fitAgeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.specificationsLabel.frame.origin.x, self.specificationsLabel.frame.origin.y+self.specificationsLabel.frame.size.height+4, self.middleView.frame.size.width*0.3, self.middleView.frame.size.height*0.2)];
    self.fitAgeLabel.textColor = UIColorWithRGBA(186, 186, 186, 1);
    self.fitAgeLabel.font = [UIFont systemFontOfSize:12];
//    fitAgeLabel.backgroundColor = [UIColor blueColor];
    [self.middleView addSubview:self.fitAgeLabel];
    
    //2.6价钱
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.specificationsLabel.frame.origin.x+self.specificationsLabel.frame.size.width+2, self.specificationsLabel.frame.origin.y, self.specificationsLabel.frame.size.width, self.specificationsLabel.frame.size.height*2)];
//    priceLabel.backgroundColor = [UIColor redColor];
    self.priceLabel.textColor = UIColorWithRGBA(232, 63, 106, 1);
    self.priceLabel.textAlignment = NSTextAlignmentRight;
    self.priceLabel.font = [UIFont systemFontOfSize:20];
    [self.middleView addSubview:self.priceLabel];

    
    //3.试用数 已申请 结束时间
    self.timeAndNumView = [[UIView alloc] initWithFrame:CGRectMake(self.middleView.frame.origin.x, self.middleView.frame.size.height+self.middleView.frame.origin.y, self.middleView.frame.size.width, self.middleView.frame.size.height*0.9)];
//    timeAndNumView.backgroundColor = [UIColor orangeColor];
    [self addSubview:self.timeAndNumView];
    
    //添加左侧的小view
    
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/2-1, self.timeAndNumView.frame.size.height*0.45)];
    leftView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"试用详情底部按钮@2x"]];
    [self.timeAndNumView addSubview:leftView];
    
    //添加左侧 试用数
    UILabel *textLeftLabel = [[UILabel alloc] initWithFrame:CGRectMake(leftView.frame.size.width*0.1, 0, leftView.frame.size.width*0.45, leftView.frame.size.height)];
    textLeftLabel.text = @"试用数：";
    textLeftLabel.textColor = UIColorWithRGBA(102, 46, 5, 1);
    [leftView addSubview:textLeftLabel];
    
    //3.1
    self.trailNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(textLeftLabel.frame.origin.x+textLeftLabel.frame.size.width, leftView.frame.size.height*0.24, leftView.frame.size.width*0.4, leftView.frame.size.height*0.45)];

    self.trailNumLabel.textColor = UIColorWithRGBA(131, 67, 14, 1);
    self.trailNumLabel.font = [UIFont boldSystemFontOfSize:20];

    [leftView addSubview:self.trailNumLabel];

    
    //添加右侧的小view
    UIView *rigthView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+2, leftView.frame.origin.y, leftView.frame.size.width,leftView.frame.size.height)];
    rigthView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"已申请框@2x"]];
    [self.timeAndNumView addSubview:rigthView];
    
    //添加右侧 已申请
    UILabel *textRightLabel = [[UILabel alloc] initWithFrame:CGRectMake(rigthView.frame.size.width*0.1, 0, rigthView.frame.size.width*0.45, rigthView.frame.size.height)];
    textRightLabel.text = @"已申请:";
    [rigthView addSubview:textRightLabel];
    
    //3.2
    self.applyLabel = [[UILabel alloc] initWithFrame:CGRectMake(textRightLabel.frame.origin.x+textRightLabel.frame.size.width,rigthView.frame.size.height*0.24,rigthView.frame.size.width*0.4,rigthView.frame.size.height*0.45)];
     self.applyLabel.textColor = UIColorWithRGBA(234, 234, 234, 1);
     self.applyLabel.font = [UIFont boldSystemFontOfSize:20];
    [rigthView addSubview:self.applyLabel];
    
    //3.3结束时间
    self.overTime = [[UILabel alloc] initWithFrame:CGRectMake(leftView.frame.size.width*0.2, leftView.frame.size.height+leftView.frame.origin.y+6, leftView.frame.size.width*1.4, leftView.frame.size.height*0.4 )];
    [self.timeAndNumView addSubview:self.overTime];
}

- (void)valueForSubviews
{
    [self.bigImageView setImageWithURL:[NSURL URLWithString:self.detailFreeModel.adImageURL]];
    [self.brandImageView setImageWithURL:[NSURL URLWithString:self.detailFreeModel.imageURL]];
    self.titlLabel.text = self.detailFreeModel.title;
    self.timeLabel.text = [NSString stringWithFormat:@"时间：%@ - %@", self.detailFreeModel.timeStart,   self.detailFreeModel.timeStop];
    self.specificationsLabel.text = [NSString stringWithFormat:@"规格：%@",self.detailFreeModel.specification];
    self.fitAgeLabel.text = [NSString stringWithFormat:@"试用年龄：%@",self.detailFreeModel.useAge];
    self.priceLabel.text = self.detailFreeModel.price;
    self.trailNumLabel.text = self.detailFreeModel.amount;
    self.applyLabel.text = self.detailFreeModel.applied;
    self.overTime.text = [NSString stringWithFormat:@"距离结束时间：%@",self.detailFreeModel.estimate];
}
@end
